package com.qc.bug.Services.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qc.bug.Dao.BugInfoMapper;
import com.qc.bug.Services.bugInfoServices;
import com.qc.bug.pojo.BugInfo;

@Service
public class bugInfoServicesImpl implements bugInfoServices {

	@Autowired
	private BugInfoMapper bugInfoDao;
	
	/**
	 * 插入bug信息
	 */
	public void addBugInfo(BugInfo buginfo) {

		bugInfoDao.addBugInfo(buginfo);

	}

	public List<Map<String, Object>> findAllBugInfo(String str) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("str", str);

		return bugInfoDao.findAllBugInfo(map);
	}

	public List<Map<String, Object>> findBydescription(String description,
			int pageIndex, int pageSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("description", description);
		map.put("index", (pageIndex - 1) * pageSize);
		map.put("pageSize", pageSize);

		return bugInfoDao.findBydescription(map);
	}

	public BugInfo findById(int bugId) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("bugId", bugId);
		BugInfo buginfo=bugInfoDao.findById(map);
		if(null!=bugInfoDao.findById(map)){
			 buginfo.setQueriesnumber((buginfo.getQueriesnumber()+1));
			bugInfoDao.updateQueriesnumber(buginfo);
		}
		return buginfo;
	}

	/**
	 * 获取分页查询的页面数量
	 */
	public int getPageNumber(String description, int pageSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("description", description);
		int total = bugInfoDao.getTotal(map);
		if (total % pageSize == 0) {
			return total / pageSize;
		} else {
			return total / pageSize + 1;
		}
	}

	/**
	 * 分页查询用户添加的bug信息
	 */
	public List<Map<String,Object>> findByUserId(int userid,int pageIndex2, int pageSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("addpeopleid", userid);
		map.put("index", pageIndex2);
		map.put("pageSize", pageSize);
		
		return bugInfoDao.findByAddPeopleId(map);
	}

	/**
	 * 查询用户插入信息的总条数
	 */
	public int getAddBugTotal(int userid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("addpeopleid", userid);
		return bugInfoDao.getAddTotal(map);
	}

	/**
	 * 删除bug
	 */
	public int deleteBYId(int bugId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("bugId", bugId);
		
		
		return bugInfoDao.deleteBYId(map);
	}

	/**
	 * 修改buginfo
	 */
	public int updateBugInfo(BugInfo buginfo) {
		
		return bugInfoDao.updateBugInfo(buginfo);
	}

}
